//
//  SCMyOrderController.m
//  shangcheng
//
//  Created by 张艳江 on 2019/6/3.
//  Copyright © 2019 张艳江. All rights reserved.
//

#import "SCMyOrderController.h"
#import "ZJScrollPageView.h"
#import "SCOrderListController.h"

@interface SCMyOrderController ()<ZJScrollPageViewDelegate>

@property (strong, nonatomic) NSArray *titles;

@end

@implementation SCMyOrderController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"我的订单";
    self.view.backgroundColor = BGColor;
    
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem barButtonItemWithImage:[UIImage imageNamed:@"back"] target:self action:@selector(back)];
    // 初始化
    [self setupSegmentView];
}
- (void)back{
    [self.navigationController popToRootViewControllerAnimated:YES];
}
- (void)setupSegmentView{
    
    ZJSegmentStyle *style = [[ZJSegmentStyle alloc] init];
    style.showLine = YES;//显示遮盖
    style.scrollLineColor = RGB(195, 0, 11);
    style.titleFont = SCFont(14);
    style.segmentHeight = 38;
    // 当标题(和图片)宽度总和小于ZJScrollPageView的宽度的时候, 标题会自适应宽度
    style.autoAdjustTitlesWidth = YES;
    style.contentViewBounces = NO;
    style.gradualChangeTitleColor = YES;// 颜色渐变
    style.normalTitleColor = RGB(96, 96, 96);
    style.selectedTitleColor = RGB(195, 0, 11);
    self.titles = @[@"全部", @"待付款", @"待发货", @"待收货", @"待评价"];
    // 初始化
    ZJScrollPageView *scrollPageView = [[ZJScrollPageView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH - kTopHeight) segmentStyle:style titles:self.titles parentViewController:self delegate:self];
    [scrollPageView setSelectedIndex:self.index animated:NO];
    [self.view addSubview:scrollPageView];
    
    
    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 0.5)];
    lineView.backgroundColor = RGBA(239, 239, 239, 239);
    [self.view addSubview:lineView];
}
#pragma mark - 代理
- (NSInteger)numberOfChildViewControllers {
    return self.titles.count;
}
- (UIViewController<ZJScrollPageViewChildVcDelegate> *)childViewController:(UIViewController<ZJScrollPageViewChildVcDelegate> *)reuseViewController forIndex:(NSInteger)index{
    
    UIViewController<ZJScrollPageViewChildVcDelegate> *childVc = reuseViewController;
    
    if (!childVc) {
        childVc = self.childVcs[index];
    }
    return childVc;
}
- (NSArray *)childVcs{
    
    SCOrderListController *vc0 = [[SCOrderListController alloc]init];
    vc0.status = @"0";
    
    SCOrderListController *vc1 = [[SCOrderListController alloc]init];
    vc1.status = @"1";
    
    SCOrderListController *vc2 = [[SCOrderListController alloc]init];
    vc2.status = @"2";
    
    SCOrderListController *vc3 = [[SCOrderListController alloc]init];
    vc3.status = @"3";
    
    SCOrderListController *vc4 = [[SCOrderListController alloc]init];
    vc4.status = @"4";
    
    NSArray *childVcs = @[vc0, vc1, vc2, vc3, vc4] ;
    return childVcs;
}


@end
